package com.googlecode.iiddefecttracker.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.googlecode.iiddefecttracker.domain.Project;
import com.googlecode.iiddefecttracker.service.ProjectService;

/**
 * I am {@link Controller} for project page.
 */
public class ProjectController implements Controller {
    
    private final ProjectService projectService;
    
    public ProjectController(final ProjectService projectService) {
        this.projectService = projectService;
    }
    
    public ModelAndView handleRequest(final HttpServletRequest request,
            final HttpServletResponse response) throws Exception {
        
        final List<Project> projectsFound = projectService.findProjects();
        
        final Map<String, Object> projectPageModel = new HashMap<String, Object>();
        projectPageModel.put("projects", projectsFound);
        
        return new ModelAndView("projects", "model", projectPageModel);
    }
    
}
